<?php
//Database connection
abstract class Connect{
	protected $host = 'gator3109.hostgator.com';
	protected $user;
	protected $password;
	protected $database = 'worldcl7_WG101';
	protected $message;
	public function __construct(){
		$host = $this->host;
		$user = $this->user;
		$password = $this->password;
		$database = $this->database;
		$message = $this->message;
		$knek = mysqli_connect($this->host, $this->user, $this->password, $this->database);
		mysqli_query($knek, "SET NAMES utf8");
		mysqli_query($knek, "SET CHARACTER SET utf8");
		if(mysqli_connect_errno()) die('Cannot connect to MySQL.');
		else echo '<h2>'.$message.'</h2>';		
	}
}
class KnekSudo extends Connect{
	protected $user = 'worldcl7_wg1sudo';
	protected $password = 'wg1sudo-8686';
	protected $message = 'Connected as Super Administrator';
	static private $countArray = array();
	static public function counter(){
		array_push(self::$countArray, $this);
		echo 'You\'ve created this object '.count(self::$countArray).' times';	
	}
}
class KnekAdmin extends Connect{
	protected $user = 'worldcl7_admin';
	protected $password = 'admin-8686';
	protected $message = 'Now connected as User Administrator';
}
class KnekCust extends Connect{
	protected $user = 'worldcl7_cust';
	protected $password = 'customer-8686';
	protected $message = 'Now connected as Customer';	
}
class KnekBusi extends Connect{
	protected $user = 'worldcl7_busi';
	protected $password = 'business-8686';
	protected $message = 'Now connected as a Business';	
}
abstract class wg101{ //Parent class for database objects
	public function set_query($array){
		$tableName = array_keys($array);
		$query = 'INSERT INTO '.$tableName[0].' (';
		array_shift($array);
		$values = '';
		foreach($array as $key=>$value){
			$query .= $key.', ';
			$values .= $value.', ';
		}
		$query = rtrim($query, ', ');
		$values = rtrim($values, ', ');
		$query .= ') VALUES ('.$values.')';
		echo $query;			
	}
	public function get_query_by_id($array, $pvalue){
		$tableName = array_keys($array);
		$query = 'SELECT ';
		array_shift($array);
		$tables = '';
		foreach($array as $key=>$value){
			$tables .= $key.', ';
		}
		$tables = rtrim($tables, ', ');
		$query .= $tables.' FROM '.$tableName[0].' WHERE '.$tableName[1].' = '.$pvalue;
		echo $query;
	}
}
class product extends wg101{
	public $product_id;
	public $product_sn_id;
	public $product_qr_code_id;
	public $date;
	public $void;
	public function dtime(){ //Adds a time to the 'date' property
		return $this->date = date('Y-m-d h-i-s', mktime());
	}
	/* Taking care of the pricing [^_^] */
	public function price(){
		$price_id;
		$cost_id;
		$msrp_id;
		$street_price_id;	
	}
	public function cost(){
		$cost;
	}
	public function msrp(){
		$msrp;
	}
	public function street_price($product_id=0){
		$astreet_price = array('product_street_prices' => '', 'product_street_price_id' => '\'\'', 'product_street_price' => '999.99', 'date' => $this->dtime(), 'added_by' => 'Add admin ID here');
		$command = 'SELECT product_street_price_id, product_street_price, date, added_by FROM product_street_prices';
		/* $command = "INSERT INTO product_street_prices (product_street_price_id, product_street_price, date, added_by)
		VALUES('', '999.99', '".$this->dtime()."', 'Add admin ID here')"; */
		echo $command;
		echo '<pre>';
		print_r($astreet_price);
		echo '</pre>';
		parent::set_query($astreet_price);
		echo '<hr />';
		parent::get_query_by_id($astreet_price, 3);
		/* 
			Needs the be able to get_query_value (modify the get_query_by_id to support this)
		*/
	}
}
$product = new Product();
$product->street_price();
/*
$sudo = new KnekSudo();
$sudo->counter();
$admin = new KnekAdmin();
$customer = new KnekCust();
$business = new KnekBusi();
$sudo1 = new KnekSudo();
$sudo1->counter();
*/
/*
	1- Create PHP API for entering a:
		a) Product price
			i) The trick here is, all 'final' object in the hieararchy
			must be have call a generic 'get_' and 'set_' method
			ii) This generic 'get_' method detects if the value of a 
			specified property already, and if it does, the '_ID' is returned
			iii) The generic 'set_' method sets a particular value
			once then returns its '_ID' (Note that a 'get_' will always be called
			before 'set_' is.
		b) Product info
		c) Product dimension
		d) Product categories and subcategories
		e) Product QR code
		f) Product SN
		g) Product classes
		h) Product quantity
	2- Filter products from a static XML document using OOPHP 
*/
?>